﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SlackOff
{
    public class TimeLeft
    {
        private DateTime startTime;

        public int Minutes { get; private set; }

        private int delayTotalMinutes = 0;

        public int DelayingMinutes { get; private set; }
        public TimeLeft(int minutes)
            : this(minutes, 0)
        {

        }

        public TimeLeft(int minutes, int delayingMinutes)
        {
            this.startTime = DateTime.MinValue;
            this.Minutes = minutes;
            this.DelayingMinutes = delayingMinutes;
        }
        public int DelayTotalMinutes => this.delayTotalMinutes;
        public void Delay()
        {
            this.delayTotalMinutes += this.DelayingMinutes;
        }
        public TimeLeftResult GetTimeLeft()
        {
            if (!this.IsStarted)
            {
                return new TimeLeftResult(this.Minutes * 60);
            }

            var ts = DateTime.Now - this.startTime;
            var classTimeLeft = (this.Minutes + this.delayTotalMinutes) * 60 - (int)ts.TotalSeconds;
            return new TimeLeftResult(classTimeLeft);
        }

        public void Start()
        {
            this.Reset();
            this.startTime = DateTime.Now;
        }

        public bool IsStarted => this.startTime != DateTime.MinValue;

        public DateTime StartTime => this.startTime;

        public void Reset()
        {
            this.startTime = DateTime.MinValue;
            this.delayTotalMinutes = 0;
        }

    }
}
